package com.lm.scau.framedemos.Activity;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.lm.scau.framedemos.Adapter.ImageAdapter;
import com.lm.scau.framedemos.BaseActivity;
import com.lm.scau.framedemos.R;
import com.lm.scau.framedemos.Views.LMTitleBar;
import com.lm.scau.framedemos.Views.SunmaryView;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

/**
 * Function:
 * auth：liming on 2016/7/20 10:10
 * mail：liming@wxchina.com
 */
public class PicassoActivity extends BaseActivity {
    private SunmaryView sunmaryView;
    private TextView requestTextView;
    private ListView photoListView;
    private List<String> urlList;
    private LinearLayout layout;
    private ImageAdapter imageAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_picasso);
        initView();
        urlList = new ArrayList<String>();
        initAction();
    }

    private void initAction() {
        sunmaryView.getBtnCancel().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ImageView image = new ImageView(PicassoActivity.this);
                Picasso.with(PicassoActivity.this).load("http://www.dpfile.com/s/res/app-touch-icon-152x152.ee6d0c24fc2de0f9a62b6cc9e6720393.png").error(3).placeholder(R.drawable.icon_person_header).into(image);
                layout.addView(image);
            }
        });
        sunmaryView.getBtnOk().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                urlList.clear();
                addUrls();
                imageAdapter = new ImageAdapter(PicassoActivity.this,urlList);
                photoListView.setAdapter(imageAdapter);
            }

            private void addUrls() {
                urlList.add("http://img.hb.aicdn.com/5f6c5653f06fdf58d985b98210b06084b1e846e410bd5-0PzRki_fw580");
                urlList.add("http://imgsrc.baidu.com/forum/w%3D580/sign=fcae01763b87e9504217f3642039531b/2f2eb9389b504fc29fccbeb0e4dde71191ef6df7.jpg");
                urlList.add("http://img.hb.aicdn.com/d2024a8a998c8d3e4ba842e40223c23dfe1026c8bbf3-OudiPA_fw580");
                urlList.add("http://imgsrc.baidu.com/forum/pic/item/41705e94a0223675b17ec557.jpg");
                urlList.add("http://a.hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=4053015da7efce1bea7ec0ce9a61dfe8/f31fbe096b63f624bbdc7ba88744ebf81b4ca39c.jpg");
                urlList.add("http://h.hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=45370217be12c8fcb4a6fec9c933be73/55e736d12f2eb938acec0ac5d2628535e5dd6f07.jpg");
                urlList.add("http://img.hb.aicdn.com/a21cfb7fcf3c2abf95996a17eb3e8827e3fd2cdaf290-x0eCVL_fw580");
                urlList.add("http://e.hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=dd3011be3dc79f3d8fb4ec348f91e127/a2cc7cd98d1001e92d0c404ebe0e7bec54e797ba.jpg");

                urlList.add("http://img.hb.aicdn.com/5f6c5653f06fdf58d985b98210b06084b1e846e410bd5-0PzRki_fw580");
                urlList.add("http://imgsrc.baidu.com/forum/w%3D580/sign=fcae01763b87e9504217f3642039531b/2f2eb9389b504fc29fccbeb0e4dde71191ef6df7.jpg");
                urlList.add("http://img.hb.aicdn.com/d2024a8a998c8d3e4ba842e40223c23dfe1026c8bbf3-OudiPA_fw580");
                urlList.add("http://imgsrc.baidu.com/forum/pic/item/41705e94a0223675b17ec557.jpg");
                urlList.add("http://a.hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=4053015da7efce1bea7ec0ce9a61dfe8/f31fbe096b63f624bbdc7ba88744ebf81b4ca39c.jpg");
                urlList.add("http://h.hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=45370217be12c8fcb4a6fec9c933be73/55e736d12f2eb938acec0ac5d2628535e5dd6f07.jpg");
                urlList.add("http://img.hb.aicdn.com/a21cfb7fcf3c2abf95996a17eb3e8827e3fd2cdaf290-x0eCVL_fw580");
                urlList.add("http://e.hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=dd3011be3dc79f3d8fb4ec348f91e127/a2cc7cd98d1001e92d0c404ebe0e7bec54e797ba.jpg");

                urlList.add("http://img.hb.aicdn.com/5f6c5653f06fdf58d985b98210b06084b1e846e410bd5-0PzRki_fw580");
                urlList.add("http://imgsrc.baidu.com/forum/w%3D580/sign=fcae01763b87e9504217f3642039531b/2f2eb9389b504fc29fccbeb0e4dde71191ef6df7.jpg");
                urlList.add("http://img.hb.aicdn.com/d2024a8a998c8d3e4ba842e40223c23dfe1026c8bbf3-OudiPA_fw580");
                urlList.add("http://imgsrc.baidu.com/forum/pic/item/41705e94a0223675b17ec557.jpg");
                urlList.add("http://a.hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=4053015da7efce1bea7ec0ce9a61dfe8/f31fbe096b63f624bbdc7ba88744ebf81b4ca39c.jpg");
                urlList.add("http://h.hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=45370217be12c8fcb4a6fec9c933be73/55e736d12f2eb938acec0ac5d2628535e5dd6f07.jpg");
                urlList.add("http://img.hb.aicdn.com/a21cfb7fcf3c2abf95996a17eb3e8827e3fd2cdaf290-x0eCVL_fw580");
                urlList.add("http://e.hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=dd3011be3dc79f3d8fb4ec348f91e127/a2cc7cd98d1001e92d0c404ebe0e7bec54e797ba.jpg");
            }
        });
    }

    private void initView() {
        mTitleBar = (LMTitleBar) findViewById(R.id.titlebar);
        sunmaryView = (SunmaryView) findViewById(R.id.sunmary_view);
        requestTextView = (TextView) findViewById(R.id.text_view_request_info);
        photoListView = (ListView) findViewById(R.id.photo_list_view);
        layout = (LinearLayout) findViewById(R.id.image_linear_layout);
        layout.setPadding(5,5,5,5);
        mTitleBar.setTitle("Picasso");
        sunmaryView.setTitle("Picasso");
        sunmaryView.setSunmary("picasso是Square公司开源的一个Android图片下载缓存库，github地址https://github.com/square/picasso，可以实现图片下载和缓存功能。");
        sunmaryView.getBtnOk().setText("列表图片显示");
        sunmaryView.getBtnCancel().setText("单个图片显示");
    }
}
